package com.seteam.collabcrossword.windows;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ProgressWindow extends JFrame {
    private final Logger logger = LoggerFactory.getLogger(ProgressWindow.class);
    private Container container;
    private JProgressBar progressBar;
    private Timer timer;
    private int progress;
    private JLabel label;
    private int count;

    public ProgressWindow() {
        super("Starting Game");
        progress = 0;
        count = 0;
        init();
    }

    private void init() {
        final String[] messages = {"Connecting", "Requesting For Board", "Rendering UI", "Ready To Play"};
        progressBar = new JProgressBar();
        progressBar.setValue(0);
        progressBar.setStringPainted(true);

        label = new JLabel("Processing");
        label.setLabelFor(progressBar);

        container = getContentPane();
        container.setLayout(new FlowLayout(FlowLayout.CENTER));
        container.add(progressBar);
        container.add(label);

        setSize(640, 480);
        setVisible(true);

        timer = new Timer(1000, new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent actionEvent) {
                if(progress == 100) {
                    timer.stop();
                } else {
                    progress += 25;
                    progressBar.setValue(progress);
                    label.setText(messages[count++]);
                }

            }
        });

        timer.start();
    }
}
